﻿using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Sidvall.AuthorizationManager.Data
{
	public static class ClaimManager
	{
		#region Public Members

		#region GetClaims

		public static Collection<Claim> GetClaims(IEnumerable<IAuthorizationScopeResourceActionClaim> items)
		{
			Collection<Claim> claims;
			Claim claim;

			claims = new Collection<Claim>();
			if (items != null)
			{
				foreach (var item in items)
				{
					claim = new Claim()
					{
						ClaimType = item.ClaimType,
						ComparisonOperator = item.ComparisonOperator,
						IsEnabled = item.IsEnabled,
						Value = item.Value,
					};
					claims.Add(claim);
				}
			}
			return claims;
		}
		public static Collection<Claim> GetClaims(IEnumerable<IAuthorizationScopeResourceItemClaim> items)
		{
			Collection<Claim> claims;
			Claim claim;

			claims = new Collection<Claim>();
			if (items != null)
			{
				foreach (var item in items)
				{
					claim = new Claim()
					{
						ClaimType = item.ClaimType,
						ComparisonOperator = item.ComparisonOperator,
						IsEnabled = item.IsEnabled,
						Value = item.Value,
					};
					claims.Add(claim);
				}
			}
			return claims;
		}

		#endregion
		#region Initialize

		public static void Initialize(Sidvall.Security.ClaimCollection items)
		{
			if (items == null)
				return;
			items.Clear();
			items.Add(Sidvall.Security.ClaimTypes.Email, string.Empty);
			items.Add(Sidvall.Security.ClaimTypes.Name, string.Empty);
			items.Add(Sidvall.Security.ClaimTypes.Role, string.Empty);
			items.Add(Sidvall.Security.ClaimTypes.Subject, string.Empty);
		}

		#endregion
		#region InitializeUserClaims

		public static void InitializeUserClaims(Sidvall.Security.ClaimCollection items)
		{
			if (items == null)
				return;
			items.Clear();
			items.Add(Sidvall.Security.ClaimTypes.Role, string.Empty);
		}

		#endregion

		#endregion
	}
}
